Public Class frmRECALL
    Dim FromDate As Date
    Dim ToDate As Date
    Private Sub btnFrom_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFrom.Click
        Dim frm As New frmCalendar
        frm.ShowDialog()
        FromDate = frm.Calendar2.SelectionRange.Start
        txtFromDate.Text = FromDate.ToString(PublicVariable.DateTimeFormat)
        SEARCH()
    End Sub

    Private Sub btnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClose.Click
        Me.Close()
    End Sub

    Private Sub btnTo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTo.Click
        Dim frm As New frmCalendar
        frm.ShowDialog()
        ToDate = frm.Calendar2.SelectionRange.Start
        txtToDate.Text = ToDate.ToString(PublicVariable.DateTimeFormat)
        If FromDate > ToDate Then
            SystemFunction.ShowMessageForm("TO DATE MUST BE GREATER THAN FROM DATE!", "")
            txtToDate.Text = txtFromDate.Text
            ToDate = FromDate
        End If
        SEARCH()
    End Sub


    Private Sub SEARCH()
        Dim dv As New DataView(oOrder.Bill_Search(FromDate, ToDate))
        dv.RowFilter = "BILL_STATUS=2"
        GridRecall.DataSource = dv
    End Sub

    Private Sub frmRECALL_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
        Try
            GC.Collect()
            Me.Dispose()
        Catch ex As Exception

        End Try
    End Sub
    Private Sub frmRECALL_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        PublicFunction.NewFormLoad(Me)

        Me.GridRecall.RootTable.Columns("BILL_TOTAL").FormatString = PublicVariable.NumberFormatString
        Me.GridRecall.RootTable.Columns("BILL_DATE").FormatString = PublicVariable.DateTimeFormat

        Me.GridDetail.RootTable.Columns("QUANTITY").FormatString = PublicVariable.NumberFormatString
        Me.GridDetail.RootTable.Columns("PRICE").FormatString = PublicVariable.NumberFormatString
        Me.GridDetail.RootTable.Columns("LINE_TOTAL").FormatString = PublicVariable.NumberFormatString
        Me.GridDetail.RootTable.Columns("LINE_TOTAL").TotalFormatString = PublicVariable.NumberFormatString
        FromDate = PublicVariable.SystemDate
        ToDate = PublicVariable.SystemDate
        txtFromDate.Text = FromDate.ToString(PublicVariable.DateTimeFormat)
        txtToDate.Text = ToDate.ToString(PublicVariable.DateTimeFormat)
        SEARCH()
    End Sub

    Private Sub GridRecall_SelectionChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GridRecall.SelectionChanged
        GridDetail.DataSource = oOrder.LoadBillDetail(GridRecall.GetValue("BILL_CODE")).DefaultView
    End Sub

    Private Sub btnRefund_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRefund.Click
        If GridRecall.CurrentRow Is Nothing Then Return
        If SystemFunction.ShowYesNoForm("ARE YOU SURE YOU WANT TO REFUND THIS BILL?", "") = Windows.Forms.DialogResult.Yes Then
            Dim BILLCODE As Integer = GridRecall.GetValue("BILL_CODE")
            If PublicVariable.ReceiptPrintAuto = "1" Then
                Dim oPrint As New oPrint
                oPrint.PrintSlip(BILLCODE, False, PublicVariable.ReceiptPrintFilePath, PublicVariable.ReceiptPrintName, 1)
            End If
            oOrder.BILL_REFUND(BILLCODE)
            SEARCH()
        End If
        
    End Sub
End Class